/** EncounterSim is a simulator that estimates player health at the end of an encounter */
import java.util.Vector;

public class EncounterSim
{
	public void go()
	{
		
		System.out.println("Starting...");
		int iIterations =1000;
		boolean bVerbose = false;
		
		
		int[] aRounds = new int[iIterations];
		int iRounds= 0;
		int iEncounters = 0;
		double iVictories = 0;
		for (int i = 0; i<iIterations; i++)
		{
			Encounter TheEncounter = new Encounter();
			initializeParty(TheEncounter);
			initializeMonsters(TheEncounter);
			TheEncounter.setVerbose(bVerbose);
			TheEncounter.resolveCombat();
			aRounds[i] = TheEncounter.getRounds();
			iRounds += aRounds[i];
			if(TheEncounter.getVictor() == "Adventurers")
			{
				iVictories++;
			}
			iEncounters++;
		}
		iRounds = iRounds/iEncounters; //avg
		// calculate std deviation
		double iStd = 0;
		for(int i = 0; i < iIterations; i++)
		{
			int iDelta = aRounds[i]-iRounds;
			//System.out.println(iDelta);
			iStd += Math.pow(iDelta,2);
		}
		iStd = Math.sqrt(iStd/iEncounters);
		System.out.println(iEncounters + " iterations");
		System.out.println(((iVictories / iEncounters)*100)+ "% Victorious");
		System.out.println("Average Duration: "+iRounds+ " rounds");
		System.out.println("Standard Deviation: "+iStd);
	}
	private void initializeParty(Encounter eEncounter)
	{
		Party Adventurers = new Party();
		Combatant Spike = new Combatant("Spike",20,20,20,20,35);
		//Action aPreciseStrike = new Action(5,15,0,8);
		Cleave aPreciseStrike = new Cleave(5,15,0,8);
		Spike.addAtWill(aPreciseStrike);
		Adventurers.addUnit(Spike);
		Adventurers.setName("Adventurers");
		eEncounter.addParty(Adventurers);
	}
	private void initializeMonsters(Encounter eEncounter)
	{
		Party Monsters = new Party();
		Action aOrcAttack = new Action(1,8,0,4);
		Combatant Orc1 = new Combatant("Orc1",15,15,15,15,35);
		Combatant Orc2 = new Combatant("Orc2",15,15,15,15,35);
		Orc1.addAtWill(aOrcAttack);
		Orc2.addAtWill(aOrcAttack);
		Monsters.addUnit(Orc1);
		Monsters.addUnit(Orc2);
		Monsters.setName("Monsters");
		eEncounter.addParty(Monsters);
	}
	
	public static void main(String[] args)
	{
		EncounterSim eOurEncounter = new EncounterSim();
		eOurEncounter.go();
	}

}

